import { FieldType, DataSetSelection} from 'choerodon-ui/pro/lib/data-set/enum';
import Record from 'choerodon-ui/pro/lib/data-set/Record';
import {DataSet} from 'choerodon-ui/pro';

interface changeProps {
  record: Record;
  name: string;
  value: string;
  oldValue: string;
}



const optionData = [
  { text: 'Jack', value: 'jack' },
  { text: 'Huazhen', value: 'huazhen' },
  { text: 'Lucy', value: 'lucy' },
  { text: 'Niu', value: 'jiaqin' },
  { text: 'Shao', value: 'shao' },
];

const data = [{
  'first-name': 'huazhen',
  'last-name': 'wu',
}];

const optionDs = new DataSet({
  data: optionData,
  selection: DataSetSelection.single,
});

function handleDataSetChange({ record, name, value, oldValue }: changeProps) {
  console.log('[dataset newValue]', value, '[oldValue]', oldValue, `[record.get('${name}')]`, record.get(name));
}

const inputDs = () => ({
  data,
  fields: [
    { name: 'first-name', type: FieldType.string, label: '名', textField: 'text', valueField: 'value', options: optionDs },
    { name: 'last-name', type: FieldType.string, label: '姓' },
  ],
  events: {
    update: handleDataSetChange,
  },
});

export default inputDs;